<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>event loop</title>
</head>
<body>
    
    <script>
    
       /*  console.log('1');

        window.setTimeout(()=>{
            console.log('timeout 1');
        },1000);

        window.setTimeout(()=>{
            console.log('timeout 2');
        },500);

        window.setTimeout(()=>{
            console.log('timeout 3');
        },2000);

        Promise.resolve()
            .then(()=>{
                console.log('promise 1');
            }).then(()=>{
                console.log('promise 2');
            });

        console.log('2');// 1 2 promise1 promise2 timeout2 timeout1 timeout3 */ 

 /*        console.log('1');

        window.setTimeout(()=>{
            console.log('timeout 1');
        },1000);

        function fn () {
            return new Promise((resolve,reject)=>{
                console.log('new Promise');
            });
        }

        fn();

        console.log('2'); */

     /*    setTimeout(function() {
            console.log('setTimeout');
        },1000)

        new Promise(function(resolve) {
            console.log('promise');
        }).then(function() {
            console.log('then'); // 不执行
        })

        console.log('console'); // promise console setTimeout */

        console.log('1');
        setTimeout(function() {
            console.log('2');
            process.nextTick(function() {
                console.log('3');
            })
            new Promise(function(resolve) {
                console.log('4');
                resolve();
            }).then(function() {
                console.log('5')
            })
        }) //  1  2 4 3 5
    
    </script>
</body>
</html>